package com.dhcc.bpm.modules.auth.granter;

import com.dhcc.bpm.modules.system.entity.UserInfo;
import com.dhcc.bpm.modules.system.service.IUserService;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.utils.Func;
import org.springframework.stereotype.Component;

/**
 * @ClassName PasswordTokenGranter
 * @Description 校验密码
 * @Author xiafayu
 * @Date 2020/2/21 0021 15:16
 * @Version V1.0
 * @Copyright: 2020 东华软件 . All rights reserved.
 **/
@Component
@AllArgsConstructor
public class CaptchaTokenGranter implements ITokenGranter {

	public static final String GRANT_TYPE = "captcha";

	private IUserService service;

	/**
	 * @Description 校验密码
	 * @Author xiafayu
	 * @Date 2020/2/24 17:40
	 * @param tokenParameter
	 * @return com.dhcc.bpm.modules.system.entity.UserInfo
	 **/
	@Override
	public UserInfo grant(TokenParameter tokenParameter) {
		String tenantId = tokenParameter.getArgs().getStr("tenantId");
		String username = tokenParameter.getArgs().getStr("username");
		String password = tokenParameter.getArgs().getStr("password");
		UserInfo userInfo = null;
		if (Func.isNoneBlank(username, password)) {
			// 根据不同用户类型调用对应的接口返回数据，用户可自行拓展
			userInfo = service.userInfo(tenantId, username, password);
		}
		return userInfo;
	}

}
